//
//  ImageTestViewController.swift
//  XMenSwift
//
//  Created by Jason on 2022/4/22.
//

import UIKit

class ImageTestViewController: UIViewController {

    @IBOutlet weak var imageView: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //首先定义一张图片
        var image = UIImage(named: "pop_bg")
        let imageW = image?.size.width ?? 0
        let imageH = image?.size.height ?? 0
        //设置拉伸图片时，需要用来填充拉伸位置的部分（下面详解）
        let insets = UIEdgeInsets(top: imageH * 0.5, left: imageW * 0.5, bottom: imageH * 0.5 - 1, right: imageW * 0.5 - 1)
        image = image?.resizableImage(withCapInsets: insets, resizingMode: UIImage.ResizingMode.tile)
        //将拉伸后的图片，给imageview和button
        imageView.contentMode = .scaleToFill
        imageView.image = image
        // Do any additional setup after loading the view.
    }


    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let PopupMenuSmallView  = PopupMenuSmallView.show(frame: CGRect(x: 100, y: 300, width: 130, height: 44 * 3))
        //首先定义一张图片
        var image = UIImage(named: "tower_ic_black_popBg")
        let imageW = image?.size.width ?? 0
        let imageH = image?.size.height ?? 0
        //设置拉伸图片时，需要用来填充拉伸位置的部分（下面详解）
        let insets = UIEdgeInsets(top: imageH * 0.5, left: imageW * 0.5, bottom: imageH * 0.5 - 1, right: imageW * 0.5 - 1)
        image = image?.resizableImage(withCapInsets: insets, resizingMode: UIImage.ResizingMode.tile)
        //将拉伸后的图片，给imageview和button
        PopupMenuSmallView.bgImageView.contentMode = .scaleToFill
        PopupMenuSmallView.bgImageView.image = image
        PopupMenuSmallView.menuItems = [
            PopupMenuItemModel.init(title: "扫描需求", image: UIImage.init(named: "icon_match"), titleFont: 15, rowHeight: 44, titleColor: .white),
            PopupMenuItemModel.init(title: "扫描需求", image: UIImage.init(named: "icon_match"), titleFont: 15, rowHeight: 44, titleColor: .white),
            PopupMenuItemModel.init(title: "扫描需求", image: UIImage.init(named: "icon_match"), titleFont: 15, rowHeight: 44, titleColor: .white),
            PopupMenuItemModel.init(title: "扫描需求", image: UIImage.init(named: "icon_match"), titleFont: 15, rowHeight: 44, titleColor: .white),
            PopupMenuItemModel.init(title: "扫描需求", image: UIImage.init(named: "icon_match"), titleFont: 15, rowHeight: 44, titleColor: .white),
                                        
        ]
        self.view.addSubview(PopupMenuSmallView)
    }
}
